/**
 * Created by isoft-work 5 on 12/6/2014.
 */
$(document).ready(function(){
//   render
   renderWomen();
//   event
   bindEventWomen();
});

function renderWomen() {
   getListMenuWomen();
}

function getListMenuWomen() {
   ISS.BACKEND.request({
      url: ISS.SESSION.getSession('contextPath') + '/service/women/getListMenu',
      type: 'GET',
      success: function (data) {
         var responseInfo = data.responseObject;
         getListMenuWomenComplete(responseInfo);
      }
   });
}

function bindEventWomen() {

}

function getListMenuWomenComplete(listDanhMuc){
   var template = '', list = '', listLast = '', index = Math.floor((Math.random() * listDanhMuc.length - 1) + 1);;
   // first
   var _loaiDanhMucSanPham = listDanhMuc[index].loaiDanhMucSanPham;
   var item = '';
   for(var j = 0; j < _loaiDanhMucSanPham.length; j++) {
      var _href = ISS.SESSION.getSession('contextPath') + '/service/product/toPageProduct/'+ ISS.SESSION.getSession('session_gender') + '/' + _loaiDanhMucSanPham[j].maLoaiDMSP;
      item += ISS.STRING_UTIL.format(TEMPLATE.Women.item,{
         href: _href,
         danhMucSP: _loaiDanhMucSanPham[j].tenLoaiDMSP,
         id: _loaiDanhMucSanPham[j].maLoaiDMSP
      });
   }
   list = ISS.STRING_UTIL.format(TEMPLATE.Women.list,{
      danhMuc: listDanhMuc[index].tenLoai,
      item: item
   });

   var itemLast = '';
   for(var i = 0; i < listDanhMuc.length; i++){
      if(i != index){
         itemLast += ISS.STRING_UTIL.format(TEMPLATE.Women.itemLast,{
            danhMuc: listDanhMuc[i].tenLoai
         });
      }
   }
   listLast = ISS.STRING_UTIL.format(TEMPLATE.Women.listLast,{
      item: itemLast
   });
      // add menu
   template = list + listLast;
   ISS.DOM.html('#Categories_left', template);
   }
